<?php

namespace App\Admin\Actions\QRcode;

use App\Models\ProductsSaleModel;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Admin;
use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class SaleCode extends RowAction
{
    public $name = '二维码';

    public function handle(Model $model)
    {
        // $model ...

        return $this->response()->success('Success message.')->refresh();
    }

    public function form(ProductsSaleModel $model)
    {
        //生成二维码
        $code = $model['code'];
        if ($model['sale_type'] == 1) {//流通
            $code = $model['ProductBatch']['source_code'];
        }
        $url = route('admin.scan.result', ['code' => $code]);
        $this->display("d");
//        $this->html();
//        $this->append(QrCode::size(100)->generate("d"));
//        $this->render(QrCode::size(100)->generate($url));
//        QrCode::size(100)->generate($url);
//        dump(QrCode::size(100)->generate($url));exit;
//        dump($url);
//        dump($model->toArray());
    }

    public function display($value)
    {
        parent::display($value); // TODO: Change the autogenerated stub
        return QrCode::size(100)->generate("d");
    }

    public function html()
    {
        return Admin::html(QrCode::size(100)->generate("d"));
    }
}
